﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.ModBus;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Inovance
{
	/// <summary>
	/// 汇川的网络通信协议，适用于AM400、 AM400_800、 AC800 等系列，底层走的是MODBUS-TCP协议，地址说明参见标记<br />
	/// Huichuan's network communication protocol is applicable to AM400, AM400_800, AC800 and other series. The bottom layer is MODBUS-TCP protocol. For the address description, please refer to mark
	/// </summary>
	/// <remarks>
	/// AM400_800 的元件有 Q 区，I 区，M 区这三种，分别都可以按位，按字节，按字和按双字进行访问，在本组件的条件下，仅支持按照位，字访问。<br />
	/// 对于AM400_800系列的地址表如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>地址范围</term>
	///     <term>地址进制</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>输出</term>
	///     <term>Q</term>
	///     <term>Q0.0-Q8191.7 或是 Q0-Q65535</term>
	///     <term>8 或是 10</term>
	///     <term>位读写</term>
	///   </item>
	///   <item>
	///     <term>输入</term>
	///     <term>I</term>
	///     <term>IX0.0-IX8191.7 或是 I0-I65535</term>
	///     <term>8 或是 10</term>
	///     <term>位读写</term>
	///   </item>
	///   <item>
	///     <term>M寄存器</term>
	///     <term>M</term>
	///     <term>MW0-MW65535</term>
	///     <term>10</term>
	///     <term>按照字访问的</term>
	///   </item>
	/// </list>
	/// 针对AM600的TCP还支持下面的两种地址读写
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>地址范围</term>
	///     <term>地址进制</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term></term>
	///     <term>SM</term>
	///     <term>SM0.0-SM8191.7 或是 SM0-SM65535</term>
	///     <term>10</term>
	///     <term>位读写</term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>SD</term>
	///     <term>SDW0-SDW65535</term>
	///     <term>10</term>
	///     <term>字读写</term>
	///   </item>
	/// </list>
	/// </remarks>
	// Token: 0x02000094 RID: 148
	public class InovanceAMTcp : ModbusTcpNet
	{
		/// <summary>
		/// 实例化一个安川AM400-AM800系列的网络通讯协议<br />
		/// Instantiate a network communication protocol of Yaskawa AM400-AM800 series
		/// </summary>
		// Token: 0x06000B2F RID: 2863 RVA: 0x0004272E File Offset: 0x0004092E
		public InovanceAMTcp()
		{
		}

		/// <summary>
		/// 指定服务器地址，端口号，客户端自己的站号来实例化一个安川AM400-AM800系列的网络通讯协议<br />
		/// Specify the server address, port number, and client's own station number to instantiate a Yaskawa AM400-AM800 series network communication protocol
		/// </summary>
		/// <param name="ipAddress">服务器的Ip地址</param>
		/// <param name="port">服务器的端口号</param>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000B30 RID: 2864 RVA: 0x00042738 File Offset: 0x00040938
		public InovanceAMTcp(string ipAddress, int port = 502, byte station = 1) : base(ipAddress, port, station)
		{
		}

		/// <summary>
		/// 按字读取汇川PLC的数据信息，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SDW100地址数据<br />
		/// Read Huichuan PLC's data information by word. For the case of AM400_800, you can enter MW0 and MW100. For AM600, it also supports SDW0 and SDW100 address data.
		/// </summary>
		/// <param name="address">PLC的真实的地址信息，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SD2100地址数据</param>
		/// <param name="length">读取的数据的长度，按照字为单位</param>
		/// <returns>包含是否成功的结果对象信息</returns>
		// Token: 0x06000B31 RID: 2865 RVA: 0x00042748 File Offset: 0x00040948
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Read(operateResult.Content, length);
			}
			return result;
		}

		/// <summary>
		/// 按字写入汇川PLC的数据信息，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SDW100地址数据<br />
		/// Write the data information of Huichuan PLC by word. For the case of AM400_800, you can enter MW0 and MW100. For AM600, it also supports SDW0 and SDW100 address data.
		/// </summary>
		/// <param name="address">PLC的真实的地址信息，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SD2100地址数据</param>
		/// <param name="value">等待写入的原始数据，长度为2的倍数</param>
		/// <returns>是否写入成功的结果信息</returns>
		// Token: 0x06000B32 RID: 2866 RVA: 0x00042788 File Offset: 0x00040988
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000B33 RID: 2867 RVA: 0x000427C8 File Offset: 0x000409C8
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			InovanceAMTcp.<ReadAsync>d__4 <ReadAsync>d__ = new InovanceAMTcp.<ReadAsync>d__4();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<InovanceAMTcp.<ReadAsync>d__4>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000B34 RID: 2868 RVA: 0x0004281C File Offset: 0x00040A1C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			InovanceAMTcp.<WriteAsync>d__5 <WriteAsync>d__ = new InovanceAMTcp.<WriteAsync>d__5();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceAMTcp.<WriteAsync>d__5>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 按位读取汇川PLC的数据信息，对于AM400_800的情况，可以输入QX0.1，IX0.1，对于AM600而言，还支持SMX0.1地址数据<br />
		/// Read the data of Huichuan PLC bit by bit. For the case of AM400_800, you can enter QX0.1 and IX0.1. For AM600, it also supports SMX0.1 address data.
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，对于AM400_800的情况，可以输入QX0.1，IX0.1，对于AM600而言，还支持SMX0.1地址数据</param>
		/// <param name="length">等待读取的长度，按照位为单位</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06000B35 RID: 2869 RVA: 0x00042870 File Offset: 0x00040A70
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 1);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.ReadBool(operateResult.Content, length);
			}
			return result;
		}

		/// <summary>
		/// 按位写入汇川PLC的数据信息，对于AM400_800的情况，可以输入QX0.1，对于AM600而言，还支持SMX0.1地址数据<br />
		/// Write the data information of Huichuan PLC bit by bit. For AM400_800, you can enter QX0.1. For AM600, it also supports SMX0.1 address data
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，对于AM400_800的情况，可以输入QX0.1，对于AM600而言，还支持SMX0.1地址数据</param>
		/// <param name="values">等待写入的原始数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B36 RID: 2870 RVA: 0x000428B0 File Offset: 0x00040AB0
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, values);
			}
			return result;
		}

		/// <summary>
		/// 写入汇川PLC一个bool数据，对于AM400_800的情况，可以输入QX0.1，对于AM600而言，还支持SMX0.1地址数据<br />
		/// Write a bool data of Huichuan PLC. For the case of AM400_800, you can enter QX0.1. For AM600, it also supports SMX0.1 address data.
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，对于AM400_800的情况，可以输入QX0.1，对于AM600而言，还支持SMX0.1地址数据</param>
		/// <param name="value">bool数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B37 RID: 2871 RVA: 0x000428F0 File Offset: 0x00040AF0
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000B38 RID: 2872 RVA: 0x00042930 File Offset: 0x00040B30
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			InovanceAMTcp.<ReadBoolAsync>d__9 <ReadBoolAsync>d__ = new InovanceAMTcp.<ReadBoolAsync>d__9();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<InovanceAMTcp.<ReadBoolAsync>d__9>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000B39 RID: 2873 RVA: 0x00042984 File Offset: 0x00040B84
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			InovanceAMTcp.<WriteAsync>d__10 <WriteAsync>d__ = new InovanceAMTcp.<WriteAsync>d__10();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceAMTcp.<WriteAsync>d__10>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Boolean)" />
		// Token: 0x06000B3A RID: 2874 RVA: 0x000429D8 File Offset: 0x00040BD8
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			InovanceAMTcp.<WriteAsync>d__11 <WriteAsync>d__ = new InovanceAMTcp.<WriteAsync>d__11();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceAMTcp.<WriteAsync>d__11>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 写入汇川PLC的一个字数据，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SDW100地址数据<br />
		/// Write one word data of Huichuan PLC. For the case of AM400_800, you can enter MW0 and MW100. For AM600, it also supports SDW0 and SDW100 address data.
		/// </summary>
		/// <param name="address">汇川PLC的真实地址，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SD2100地址数据</param>
		/// <param name="value">short数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B3B RID: 2875 RVA: 0x00042A2C File Offset: 0x00040C2C
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <summary>
		/// 写入汇川PLC的一个字数据，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SDW100地址数据<br />
		/// Write one word data of Huichuan PLC. For the case of AM400_800, you can enter MW0 and MW100. For AM600, it also supports SDW0 and SDW100 address data.
		/// </summary>
		/// <param name="address">汇川PLC的真实地址，对于AM400_800的情况，可以输入MW0，MW100，对于AM600而言，还支持SDW0，SD2100地址数据</param>
		/// <param name="value">ushort数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B3C RID: 2876 RVA: 0x00042A6C File Offset: 0x00040C6C
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Int16)" />
		// Token: 0x06000B3D RID: 2877 RVA: 0x00042AAC File Offset: 0x00040CAC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, short value)
		{
			InovanceAMTcp.<WriteAsync>d__14 <WriteAsync>d__ = new InovanceAMTcp.<WriteAsync>d__14();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceAMTcp.<WriteAsync>d__14>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.UInt16)" />
		// Token: 0x06000B3E RID: 2878 RVA: 0x00042B00 File Offset: 0x00040D00
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ushort value)
		{
			InovanceAMTcp.<WriteAsync>d__15 <WriteAsync>d__ = new InovanceAMTcp.<WriteAsync>d__15();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceAMTcp.<WriteAsync>d__15>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000B3F RID: 2879 RVA: 0x00042B52 File Offset: 0x00040D52
		public override string ToString()
		{
			return string.Format("InovanceAMTcp[{0}:{1}]", this.IpAddress, this.Port);
		}
	}
}
